#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

 int main() 
 {
 	int pipefd[2]; 
 	if (pipe(pipefd) == -1)
 	{
 	 perror("pipe error");
 	 exit(-1);
 	}
 	pid_t pid;
 	pid = fork();
 	
 	if (pid == -1)
 	{
 		perror("fork error");
 		exit(-2);
 	}
 	if (pid == 0) 
 	{
 		close(pipefd[0]);
 		write(pipefd[1], "hello", 5);
 		close(pipefd[1]);
 		exit(1); //子进程成功运行
 	}
 	close(pipefd[1]);
 	char buf[10] = {0};
 	//read(pipefd[0], buf, 10);
	while(read(pipefd[0], buf, 10)) 
	{
	
	}

 	printf("buf=%s\n", buf);
 
 	return 0;
}